package com.shijie.controller.erp;

import com.shijie.service.LogisticCompanysService;
import com.shijie.domain.entity.LogisticCompanys;
import com.shijie.core.Result;
import com.shijie.core.ResultGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import tk.mybatis.mapper.entity.Condition;

import javax.annotation.Resource;

import java.util.List;

/*
 *  @author: smart boy
 *  @date: 2018-08-22
 */
@RestController
@RequestMapping("/erp/logisticcompanys")
public class LogisticCompanysController {

    @Resource
	private LogisticCompanysService logisticCompanysService;

	@GetMapping
    public Result list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size,@RequestParam(required=false) String q) {
        PageHelper.startPage(page, size);
        Condition condition = new Condition(LogisticCompanys.class);
        if(!StringUtils.isEmpty(q)){
        	condition.createCriteria().andLike("companyCn", "%"+q+"%").orLike("companyEn", "%"+q+"%");	
        }
        List<LogisticCompanys> list = logisticCompanysService.selectByCondition(condition);
        PageInfo<LogisticCompanys> pageInfo = new PageInfo<>(list);
        return ResultGenerator.success(pageInfo);
	}
}

